home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / wb-tools / time-tools / sclock / source / datatypes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-09  |  5.3 KB  |  259 lines

  1. /****************************************************************************
  2. *
  3. * VERSION
  4. *    $VER: datatypes.c 1.60 (03.12.93)
  5. *
  6. * DESCRIPTION
  7. *    Datatypes code...
  8. *
  9. * AUTHOR
  10. *    Rune Johnsrud
  11. *
  12. * COPYRIGHT
  13. *    (c) 1993 Amiga Freelancers
  14. *
  15. *****************************************************************************/
  16.  
  17. #include <exec/types.h>
  18. #include <exec/memory.h>
  19. #include <graphics/gfx.h>
  20. #include <datatypes/datatypes.h>
  21. #include <datatypes/datatypesclass.h>
  22. #include <datatypes/pictureclass.h>
  23. #include <intuition/icclass.h>
  24. #include <utility/date.h>
  25. #include <libraries/asl.h>
  26.  
  27. #include <clib/alib_protos.h>
  28. #include <clib/alib_stdio_protos.h>
  29.  
  30. #include <proto/intuition.h>
  31. #include <proto/datatypes.h>
  32. #include <proto/exec.h>
  33. #include <proto/dos.h>
  34. #include <proto/utility.h>
  35.  
  36. #include <string.h>
  37.  
  38. #include "global.h"
  39.  
  40. /****************************************************************************/
  41.  
  42. extern struct GlobalData *gd;
  43. extern struct ClockInfo *ci;
  44.  
  45. /****************************************************************************/
  46.  
  47. static WORD SyncLayout(Object *o, struct Window *win);
  48.  
  49. /****************************************************************************/
  50.  
  51.  
  52. WORD ReadDTPic(BOOL render)
  53. {
  54.     WORD errcode = NOERROR, x, y, nw, nh;
  55.     ULONG nomwidth, nomheight;
  56.     Object *o = NULL;
  57.     struct dtFrameBox *dtf = NULL;
  58.     struct FrameInfo *fri = NULL;
  59.  
  60.     dtf = AllocVec(sizeof(struct dtFrameBox), MEMF_CLEAR);
  61.     fri = AllocVec(sizeof(struct FrameInfo),  MEMF_CLEAR);
  62.  
  63.     if (dtf && fri)
  64.     {
  65.         o = NewDTObject((APTR) ci->BDRPic,
  66.                 DTA_SourceType,    DTST_FILE,
  67.                 DTA_GroupID,    GID_PICTURE,
  68.                 TAG_DONE);
  69.  
  70.         if (o)
  71.         {
  72.             if (GetDTAttrs(o,
  73.                 DTA_NominalHoriz, &nomwidth,
  74.                 DTA_NominalVert,  &nomheight,
  75.                 TAG_DONE))
  76.             {
  77.                 dtf->MethodID            = DTM_FRAMEBOX;
  78.                 dtf->dtf_FrameInfo        = fri;
  79.                 dtf->dtf_ContentsInfo    = fri;
  80.                 dtf->dtf_SizeFrameInfo    = sizeof(struct FrameInfo);
  81.  
  82.                 if (DoDTMethodA(o, NULL, NULL, (Msg) dtf) && fri->fri_Dimensions.Depth)
  83.                 {
  84.                     if ((nomwidth > 32000) || (nomwidth == 0))
  85.                         nw = fri->fri_Dimensions.Width;
  86.                     else
  87.                         nw = nomwidth;
  88.  
  89.                     if ((nomheight > 32000) || (nomheight == 0))
  90.                         nh = fri->fri_Dimensions.Height;
  91.                     else
  92.                         nh = nomheight;
  93.  
  94.                     if (nw < ci->InnerWidth)
  95.                         x = ((ci->InnerWidth - nw) / 2);
  96.                     else
  97.                         x = ci->InnerLeft;
  98.  
  99.                     if (nh < ci->InnerHeight)
  100.                         y = ((ci->InnerHeight - nh) / 2);
  101.                     else
  102.                         y = ci->InnerTop;
  103.  
  104.                     if (ci->AutoSize)
  105.                     {
  106.                         ci->Width  = nw;
  107.                         ci->Height = nh;
  108.                     }
  109.  
  110.                     if (render)
  111.                     {
  112.                         SetDTAttrs(o, NULL, NULL,
  113.                             GA_Left,    x,
  114.                             GA_Top,        y,
  115.                             GA_Width,    ci->InnerWidth,
  116.                             GA_Height,    ci->InnerHeight,
  117.                             ICA_TARGET,    ICTARGET_IDCMP,
  118.                             TAG_DONE);
  119.  
  120.                         AddDTObject(gd->ClockWindow, NULL, o, -1);
  121.                         errcode = SyncLayout(o, gd->ClockWindow);
  122.                     }
  123.                 }
  124.                 else errcode = DT_ERR_DOMETHOD;
  125.             }
  126.             else errcode = DT_ERR_GETATTRS;
  127.         }
  128.         else
  129.         {
  130.             errcode = IoErr();
  131.  
  132.             if (errcode >= DTERROR_UNKNOWN_DATATYPE)
  133.                 sprintf(gd->SysErr, GetDTString(errcode), ci->BDRPic);
  134.             else
  135.                 Fault(errcode, NULL, (STRPTR) gd->SysErr, sizeof(gd->SysErr));
  136.  
  137.             errcode = SYSERROR;
  138.         }
  139.     }
  140.     else errcode = GEN_ERR_ALLOCMEM;
  141.  
  142.     if ((gd->ClockWindow) && (render))
  143.     {
  144.         if (o) RemoveDTObject(gd->ClockWindow, o);
  145.     }
  146.     if (o)     DisposeDTObject(o);
  147.     if (fri) FreeVec(fri);
  148.     if (dtf) FreeVec(dtf);
  149.  
  150.     return errcode;
  151. }
  152.  
  153.  
  154. static WORD SyncLayout(Object *o, struct Window *win)
  155. {
  156.     BOOL done = FALSE;
  157.     WORD errcode = NOERROR;
  158.     ULONG tidata;
  159.     struct IntuiMessage *imsg;
  160.     struct TagItem *tstate, *tag;
  161.     struct TagItem *tags;
  162.     
  163.     while (!done)
  164.     {
  165.         WaitPort(win->UserPort);
  166.  
  167.         while (imsg = (struct IntuiMessage *) GetMsg(win->UserPort))
  168.         {
  169.             switch (imsg->Class)
  170.             {
  171.             case IDCMP_IDCMPUPDATE:
  172.                 tstate = tags = (struct TagItem *) imsg->IAddress;
  173.  
  174.                 while (tag = NextTagItem(&tstate))
  175.                 {
  176.                     tidata = tag->ti_Data;
  177.  
  178.                     switch (tag->ti_Tag)
  179.                     {
  180.                     case DTA_Busy:
  181.                         if (tidata)
  182.                         {
  183.                             SetWindowPointer(win,
  184.                                 WA_BusyPointer, TRUE,
  185.                                 TAG_DONE);
  186.                         }
  187.                         else
  188.                         {
  189.                             SetWindowPointer(win,
  190.                                 WA_Pointer, NULL,
  191.                                 TAG_DONE);
  192.                         }
  193.                         break;
  194.  
  195.                     case DTA_ErrorLevel:
  196.                         if (tidata)
  197.                         {
  198.                             errcode = GetTagData(DTA_ErrorNumber, NULL, tags);;
  199.  
  200.                             if (errcode >= DTERROR_UNKNOWN_DATATYPE)
  201.                                 sprintf(gd->SysErr, GetDTString(errcode), ci->BDRPic);
  202.                             else
  203.                                 Fault(errcode, NULL, (STRPTR) gd->SysErr, sizeof(gd->SysErr));
  204.  
  205.                             errcode = SYSERROR;
  206.                         }
  207.                         break;
  208.  
  209.                     case DTA_Sync:
  210.                         RefreshDTObjects(o, win, NULL, NULL);
  211.                         done = TRUE;
  212.                         break;
  213.                     }
  214.                 }
  215.                 break;
  216.             }
  217.  
  218.             ReplyMsg((struct Message *) imsg);
  219.         }
  220.     }
  221.  
  222.     return errcode;
  223. }
  224.  
  225.  
  226. ULONG ASM FReqFilter(REG (a0) struct Hook *h, REG (a2) struct FileRequester *fr, REG (a1) struct AnchorPath *ap)
  227. {
  228.     struct DataType *dtn;
  229.     ULONG use = FALSE;
  230.     static UBYTE buffer[512];
  231.     BPTR lock;
  232.  
  233.     if (ap->ap_Info.fib_DirEntryType > 0)
  234.     {
  235.         use = TRUE;
  236.         return (use);
  237.     }
  238.  
  239.     strncpy(buffer, fr->fr_Drawer, sizeof(buffer));
  240.     AddPart(buffer, ap->ap_Info.fib_FileName, sizeof(buffer));
  241.  
  242.     if (lock = Lock(buffer, ACCESS_READ))
  243.     {
  244.         if (dtn = ObtainDataTypeA(DTST_FILE, (APTR) lock, NULL))
  245.         {
  246.             if (dtn->dtn_Header->dth_GroupID == GID_PICTURE) use = TRUE;
  247.  
  248.             ReleaseDataType(dtn);
  249.         }
  250.  
  251.         UnLock(lock);
  252.     }
  253.  
  254.     return (use);
  255. }
  256.  
  257.  
  258. /* End Of File */
  259.